package cate.game.play.param;


import cate.game.play.fighter.HeroFighter;
import cate.game.play.part.FightTeam;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@NoteClass("附加技能")
public class SkillAppend {

    @NoteField("针对全体目标增加的技能")
    private List<Integer> teamSkills;

    @NoteField("针对特定原型英雄增加的技能")
    private Map<Integer,List<Integer>> heroProtoSkills;


    private List<Integer> getOrBuildHeroProtoSkill(int protoId) {
        if (heroProtoSkills == null) {
            heroProtoSkills = new HashMap<>();
        }
        return heroProtoSkills.computeIfAbsent(protoId, k -> new ArrayList<>());
    }

    private List<Integer> getHeroProtoSkill(int protoId) {
        if (heroProtoSkills == null) {
            return null;
        }
        return heroProtoSkills.get(protoId);
    }

    /**
     * 添加队伍技能(全队每个人都加)
     * @param skillTid
     */
    public void addTeamSkill(int skillTid) {
        if (teamSkills == null) {
            teamSkills = new ArrayList<>();
        }
        teamSkills.add(skillTid);
    }

    /**
     * 添加特定原型英雄的技能
     * @param protoId
     * @param skillId
     */
    public void addHeroProtoSkill(int protoId, int skillId) {
        getOrBuildHeroProtoSkill(protoId).add(skillId);
    }

    /**
     * 添加特定原型英雄的技能
     * @param protoId
     * @param skills
     */
    public void addHeroProtoSkill(int protoId, List<Integer> skills) {
        getOrBuildHeroProtoSkill(protoId).addAll(skills);
    }

    /** 处理队伍 */
    public void beforeFight(FightTeam ft) {
        for (HeroFighter f : ft.getAllHero()) {
            f.skill.addSkills(teamSkills);
            f.skill.addSkills(getHeroProtoSkill(f.protoId));
        }
    }
}
